﻿using System;
using System.Collections.Generic;
using System.Text;
using EmbeddedSharp;
using EmbeddedSharp.Core;

namespace EmbeddedSharp.Core.Function.String {

    /// <summary>
    /// greeting = Concat("Hello, ", "world!"); # Hello, world!
    /// </summary>
    public class ConcatNode : FuncNode {

        public ConcatNode()
            : base() {
            base.Value = "concat";
        }

        public override object Evaluate() {
            if (Parameters.Count < 0)
            {
                throw new ArgumentException(
                    "usage: concat(expr, expr2)");
            }

            StringBuilder buff = new StringBuilder();

            foreach (Node child in Parameters) {
                buff.Append(child.Evaluate());
            }

            return buff.ToString();
        }
    }
}
